package com.airlines.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.airlines.common.R;
import com.airlines.system.domain.SysMenu;
import com.airlines.system.service.SysMenuService;
import com.airlines.system.service.SysTypeService;
import com.airlines.system.vo.SysMenuVo;

/**
 * @ClassName TypeController
 * @Description 权限管理模块-系统菜单管理控制器
 * @Author zhoujian
 * @Date 2018/9/18
 * @Version 1.0
 */

@Controller
@RequestMapping(value = "/api/system/menu")
public class MenuController {

	@Autowired
	private SysMenuService sysMenuService;
	@Autowired
	private SysTypeService sysTypeService;

	/**
	 * 进入系统菜单管理页面
	 */
	@RequestMapping(value = "{typeId}")
	public String toPage(@PathVariable String typeId, Model model) {
		model.addAttribute("type", sysTypeService.findById(typeId));
		return "system/accessManagement/sysMenu";
	}

	/**查询该系统所有的一二级菜单*/
	@RequestMapping(value = "list/{typeId}" , method = RequestMethod.GET)
	@ResponseBody
	public List<SysMenuVo> findAllMenu(@PathVariable("typeId") String typeId) {
		return sysMenuService.findAllByTypeId(typeId);
	}

	/**查询单条菜单信息*/
	@RequestMapping(value = "edit",method = RequestMethod.GET)
	public String toEditPage(@RequestParam String menuId,Model model){
		model.addAttribute("menu", sysMenuService.findById(menuId));
		return "system/accessManagement/sysMenuEdit";
	}

	/**删除(禁用)系统菜单*/
	@RequestMapping(value = "disable",method = RequestMethod.POST)
	@ResponseBody
	public R disable(String menuId){
		SysMenu sysMenu =new SysMenu();
		sysMenu.setId(menuId);
		sysMenu.setStatus(0L);
		sysMenuService.updateById(sysMenu);
		return R.ok("禁用成功！");
	}

	/**启用系统菜单*/
	@RequestMapping(value = "able",method = RequestMethod.POST)
	@ResponseBody
	public R able(String menuId){
		SysMenu sysMenu =new SysMenu();
		sysMenu.setId(menuId);
		sysMenu.setStatus(1L);
		sysMenuService.updateById(sysMenu);
		return R.ok("启用成功！");
	}
	/*@ApiOperation("查询该系统所有的一二级菜单和功能")
	@RequestMapping(value = "/optList", method = RequestMethod.GET)
	public ApiResponse<SysMenuVO> findAllMenu(@RequestParam("typeId") String typeId) {
		List<SysMenu> list = menuService.findAllMenuAndFunc(typeId);
		ApiResponse<SysMenuVO> response = new ApiResponse<>();
		SysMenuVO data = new SysMenuVO();
		data.setList(list);
		data.setTypeId(typeId);
		response.setData(data);
		return response;
	}

	@ApiOperation("添加该系统下的菜单")
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public ApiResponse add(@RequestParam("typeId") String typeId, @RequestBody SysMenu sysMenu) {
		ApiResponse response = new ApiResponse<>();
		sysMenu.setTypeId(typeId);
		menuService.addSysMenu(sysMenu);
		return response;
	}

	@ApiOperation("修改该系统下的菜单")
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public ApiResponse update(@RequestParam("typeId") String typeId, @RequestBody SysMenu sysMenu) {
		ApiResponse response = new ApiResponse<>();
		sysMenu.setTypeId(typeId);
		menuService.updateSysMenu(sysMenu);
		return response;
	}

	@ApiOperation("删除该系统下的菜单")
	@RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
	public ApiResponse delete(@RequestParam("typeId") String typeId, @PathVariable String id) {
		ApiResponse response = new ApiResponse<>();
		menuService.deleteSysMenu(id);
		return response;
	}*/
	
}